package cn.JHai.rbac.controller;


import cn.JHai.rbac.RequiredPermission;
import cn.JHai.rbac.domain.SystemDictionary;
import cn.JHai.rbac.domain.SystemDictionaryItem;
import cn.JHai.rbac.query.PageResult;
import cn.JHai.rbac.query.QueryObject;
import cn.JHai.rbac.service.SystemDictionaryItemService;
import cn.JHai.rbac.service.SystemDictionaryService;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("systemDictionaryItem")
public class SystemDictionaryItemController {

    @Autowired
    SystemDictionaryItemService systemDictionaryItemService;

    @Autowired
    SystemDictionaryService systemDictionaryService;

    /**
     * 显示systemDictionaryItem，运用了分页
     *
     * @param queryObject
     * @param model
     * @return
     */
    @RequestMapping("/list")
    @RequiredPermission({"获取字典明细","systemDictionaryItem:list"})
    public String list(QueryObject queryObject, Model model) {

        model.addAttribute("result1", systemDictionaryService.findAll());
        Long pid = null;
        if(queryObject.getParent_id()!=null){
            pid = queryObject.getParent_id();
            PageResult result = systemDictionaryItemService.queryByParentId(queryObject,pid);
            result.setParent_id(pid);
            model.addAttribute("result", result);
            model.addAttribute("qo",result);
            return "/systemDictionaryItem/list";

        } else {
            PageResult result = systemDictionaryItemService.query(queryObject);
            model.addAttribute("result", result);
            return "/systemDictionaryItem/list";
        }

    }
    @RequestMapping("saveOrUpdate")
    @RequiredPermission({"更新和添加字典明细","systemDictionaryItem:saveOrUpdate"})
    public String saveOrUpdate(SystemDictionaryItem systemDictionaryItem,Long parent_id) {
        systemDictionaryItemService.saveOrUpdata(systemDictionaryItem,parent_id);
        return "redirect:/systemDictionaryItem/list";
    }
}
